gusucode.com > VC++ 基于IE内核功能很齐全的浏览器(支持多标签)-源码程序 > VC++ 基于IE内核功能很齐全的浏览器(支持多标签)-源码程序/code/Explorer/IEView.cpp

    //Download by http://www.NewXing.com
// IEView.cpp : implementation file
//

#include "stdafx.h"
#include "IEView.h"
#include "mainfrm.h"

#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CIEView

IMPLEMENT_DYNCREATE(CIEView, CHtmlView)

CIEView::CIEView()
{
	//{{AFX_DATA_INIT(CIEView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT	
}

CIEView::~CIEView()
{	

}

void CIEView::DoDataExchange(CDataExchange* pDX)
{
	CHtmlView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIEView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CIEView, CHtmlView)
	//{{AFX_MSG_MAP(CIEView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIEView diagnostics

#ifdef _DEBUG
void CIEView::AssertValid() const
{
	CHtmlView::AssertValid();
}

void CIEView::Dump(CDumpContext& dc) const
{
	CHtmlView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CIEView message handlers

void CIEView::OnInitialUpdate() 
{
	//TODO: This code navigates to a popular spot on the web.
	//Change the code to go where you'd like.
	//Navigate2(_T("http://www.microsoft.com/visualc/"),NULL,NULL);
	//主动调整大小	
	GoHome();	
}

BOOL CIEView::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	cs.style=WS_CHILD|WS_VISIBLE;
	return CHtmlView::PreCreateWindow(cs);
}

void CIEView::OnTitleChange(LPCTSTR lpszText) 
{
	// TODO: Add your specialized code here and/or call the base class
	SetTabItemText(lpszText);
	m_strTitle=lpszText;
	CHtmlView::OnTitleChange(lpszText);
}

void CIEView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel) 
{
	// TODO: Add your specialized code here and/or call the base class
	CRect rc;
	GetParent()->GetClientRect(&rc);
	SendMessage(WM_SIZE,SIZE_MAXSHOW,MAKELPARAM(rc.Width(),rc.Height()));
	if(m_bActivedWnd && IsWindowVisible())
	{
		SetUrlAddress(lpszURL);
		m_strTitle=lpszURL;
		((CMainFrame*)AfxGetMainWnd())->SetWindowTextX(lpszURL);
	}
	if(!GetStatusBar())
	{
		//MessageBox("aaa");
	}
	CHtmlView::OnBeforeNavigate2(lpszURL, nFlags,	lpszTargetFrameName, baPostedData, lpszHeaders, pbCancel);
}

void CIEView::OnNavigateComplete2(LPCTSTR strURL) 
{
	// TODO: Add your specialized code here and/or call the base class
	((CMainFrame*)AfxGetMainWnd())->AddHistory(strURL,m_strTitle);
	if(m_bActivedWnd  && IsWindowVisible())
	{
		((CMainFrame*)AfxGetMainWnd())->SetWindowTextX(m_strTitle);
		SetUrlAddress(GetLocationURL());		
		COleVariant vaZoomFactor;
		ExecWB(OLECMDID_ZOOM,OLECMDEXECOPT_DONTPROMPTUSER,NULL,&vaZoomFactor);
		((CMainFrame*)AfxGetMainWnd())->SetFontSizeVal(vaZoomFactor.intVal*10+1);
	}	
	CHtmlView::OnNavigateComplete2(strURL);
}

void CIEView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel) 
{
	// TODO: Add your specialized code here and/or call the base class
	Cancel=FALSE;
	LRESULT pResult=AfxGetMainWnd()->SendMessage(WM_NEW_IEVIEW);
	CWnd* pWnd=(CWnd*)pResult;
	ASSERT(pWnd->IsKindOf(RUNTIME_CLASS(CIEView)));
	*ppDisp = ((CIEView*)pWnd)->GetApplication();
	//CHtmlView::OnNewWindow2(ppDisp, Cancel);
}

BOOL CIEView::SetTabItemText(LPCTSTR lpszItem)
{
	return ((CMainFrame*)AfxGetMainWnd())->m_wndTabCtrl.SetItemText(this,lpszItem);
}

void CIEView::ReadUrlDocument(LPCTSTR lpszUrl)
{
	//AfxMessageBox(lpszUrl);
	Navigate2(lpszUrl,NULL,NULL);	
}

void CIEView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class	
	if(bActivate && IsWindowVisible())
	{
		SetUrlAddress(GetLocationURL());
		((CMainFrame*)AfxGetMainWnd())->SetWindowTextX(m_strTitle);
		COleVariant vaZoomFactor;
		ExecWB(OLECMDID_ZOOM,OLECMDEXECOPT_DONTPROMPTUSER,NULL,&vaZoomFactor);
		((CMainFrame*)AfxGetMainWnd())->SetFontSizeVal(vaZoomFactor.intVal*10+1);
		EnableFrameButton();
	}
	m_bActivedWnd=bActivate;	
	CHtmlView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

void CIEView::SetUrlAddress(LPCTSTR lpszUrl)
{
	((CMainFrame*)AfxGetMainWnd())->m_wndAddress.SetWindowText(GetLocationURL());
}

void CIEView::OnDocumentComplete(LPCTSTR lpszURL) 
{
	// TODO: Add your specialized code here and/or call the base class	
	CHtmlView::OnDocumentComplete(lpszURL);	
}



CString CIEView::GetTitle()
{
	return m_strTitle;
}

void CIEView::OnCommandStateChange(long nCommand, BOOL bEnable) 
{
	// TODO: Add your specialized code here and/or call the base class	
	if(nCommand==1)//前进
	{		
		m_bEnableGoForward=bEnable;
	}
	if(nCommand==2)//后退
	{		
		m_bEnableGoBack=bEnable;
	}

	if(m_bActivedWnd && IsWindowVisible())
	{
		EnableFrameButton();
	}
	CHtmlView::OnCommandStateChange(nCommand, bEnable);
}

void CIEView::EnableFrameButton()
{
	((CMainFrame*)AfxGetMainWnd())->EnableGoBack(m_bEnableGoBack);
	((CMainFrame*)AfxGetMainWnd())->EnableGoForward(m_bEnableGoForward);
}